<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="title">
        <button data-url="/movie">电影</button>
        <button data-url="/music">音乐</button>
        <button data-url="/game">游戏</button>
    </div>
    <div id="view">

    </div>
    <script>
        const oBtns = document.querySelectorAll("#title button")
        const oView = document.getElementById("view")

        const routes = [
            { path: "/movie", content: "热血街区2：天空尽头" },
            { path: "/music", content: "courage" },
            { path: "/game", content: "宝可梦阿尔宙斯" },

        ]
        for (let i = 0; i < oBtns.length; i++) {
            oBtns[i].onclick = function () {
                location.hash = this.dataset.url
            }
        }
        window.onhashchange = function (e) {
            const newUrl = e.newURL.split("#")[1]
            routes.forEach(route => {
                if (route.path === newUrl) {
                    oView.textContent = route.content
                }
            })
        }   
    </script>
</body>

</html>